home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SGI Performance Co-Pilot 1.3
/
SGI Performance Co-Pilot 1.3.iso
/
dist
/
pcp.idb
/
usr
/
sbin
/
mpvis.z
/
mpvis
Wrap
Text File
|
1997-04-03
|
8KB
|
356 lines
#!/bin/sh
#
# Copyright (c) 1994 Silicon Graphics, Inc.
# ALL RIGHTS RESERVED.
#
# U.S. GOVERNMENT RESTRICTED RIGHTS LEGEND
# Use, duplication or disclosure by the Government is subject to
# restrictions as set forth in FAR 52.227.19(c)(2) or subparagraph
# (c)(1)(ii) of the Rights in Technical Data and Computer Software clause
# at DFARS 252.227-7013 and/or similar or successor clauses in the FAR,
# or the DOD or NASA FAR Supplement. Contractor/manufacturer is Silicon
# Graphics, Inc., 2011 N. Shoreline Blvd., Mountain View, CA 94039-7311.
#
# THIS SOFTWARE CONTAINS CONFIDENTIAL AND PROPRIETARY INFORMATION OF
# SILICON GRAPHICS, INC. ANY DUPLICATION, MODIFICATION, DISTRIBUTION, OR
# DISCLOSURE IS STRICTLY PROHIBITED WITHOUT THE PRIOR EXPRESS WRITTEN
# PERMISSION OF SILICON GRAPHICS, INC.
# /
#
# $Id: mpvis.sh,v 2.14 1997/03/21 08:51:15 kenmcd Exp $
#
tmp=/tmp/$$
trap "rm -f $tmp.*; exit" 0 1 2 3 15
rm -f $tmp.*
gridspace=120
cpuargs=
algorithm="k"
force=false
maxrowlen=16
verbose=false
showinst=false
version="2"
. /usr/pcp/lib/pmview-args
_usage()
{
echo >$tmp.msg 'Usage: mpvis [options] [cpuid...]
options:
-b use row:column ratio of 1:8 (soft limit)
-i show CPU numbers (version 2 only)
-r rowlen maximum number of CPUs per row (soft limit) [default 16]
-R rowlen force this number of CPUs per row
-v version generate scene for different versions of pmview [default 2]
-V verbose/diagnostic output
pmview(1) options:'
_pmview_usage >>$tmp.msg
echo >>$tmp.msg
echo 'Default title is: CPU Utilization for Host' >>$tmp.msg
_pmview_info -f $tmp.msg
}
# generate one row of the scene
#
_do_row()
{
cat <<End-of-File >>$tmp.conf
_grid 0 $y show (
_labeledbar (
_metrics (
irix.kernel.percpu.cpu.idle[$rowlist] 1000
irix.kernel.percpu.cpu.wait.total[$rowlist] 1000
End-of-File
$have_intr && echo " irix.kernel.percpu.cpu.intr[$rowlist] 1000" >>$tmp.conf
cat <<End-of-File >>$tmp.conf
irix.kernel.percpu.cpu.sys[$rowlist] 1000
irix.kernel.percpu.cpu.user[$rowlist] 1000
)
End-of-File
if $have_intr
then
echo ' _metriclabels ( "idle" "wait" "intr" "sys" "user" )' >>$tmp.conf
else
echo ' _metriclabels ( "idle" "wait" "sys" "user" )' >>$tmp.conf
fi
$showinst && echo " _instlabels away ( $labels )" >>$tmp.conf
cat <<End-of-File >>$tmp.conf
_colorlist cpu
)
)
End-of-File
}
_pmview_args "$@"
if [ "X$otherArgs" != X ]
then
while getopts "?biN:r:R:v:V" c $otherArgs # TODO - delete N for MR
do
case $c
in
b)
algorithm="b"
;;
i)
showinst=true
gridspace=60
;;
r)
maxrowlen=$OPTARG
;;
R)
maxrowlen=$OPTARG
force=true
;;
v)
version=$OPTARG
if [ $version != "1" -a $version != "2" ]
then
_pmview_error "only versions 1 and 2 supported for -v"
# NOTREACHED
fi
;;
V)
verbose=true
;;
?)
_usage
exit 1
;;
esac
done
set -- $otherArgs
shift `expr $OPTIND - 1`
[ $# -gt 0 ] && cpuargs=$@
fi
# set host and the options variable (options to pminfo - see below)
#
if [ "X$arch" != X ]
then
host=`pmdumplog -l $arch 2>/dev/null | awk '/^Performance/ {print $5}' | sed -e 's/,//g'`
[ "X$host" = X ] && host="unknown host"
host="$host (Archive $arch)"
options="$namespace -a $arch"
elif [ "X$host" != X ]
then
options="$namespace -h $host"
else
host=`hostname`
options="$namespace"
fi
[ -z "$titleArg" ] && titleArg="CPU Utilization for Host $host"
# irix.kernel.percpu.cpu.intr not always available
#
have_intr=true
num_intr=`pmprobe $options irix.kernel.percpu.cpu.intr 2>/dev/null | cut -d' ' -f 2`
[ "$num_intr" -lt 1 ] && have_intr=false
rm -f $tmp.conf
if [ $version = "1" ]
then
# pmview 1.0
#
cat <<End-of-File >$tmp.conf
# pmview 1.0
#
# mpvis
#
End-of-File
if $have_intr
then
cat <<End-of-File >>$tmp.conf
5 0 0.0 0.0 0.8 1000.0 user irix.kernel.percpu.cpu.user
4 0 0.8 0.0 0.0 1000.0 sys irix.kernel.percpu.cpu.sys
3 0 0.8 0.8 0.0 1000.0 intr irix.kernel.percpu.cpu.intr
2 0 0.0 0.8 0.8 1000.0 wait irix.kernel.percpu.cpu.wait.total
1 0 0.0 0.8 0.0 1000.0 idle irix.kernel.percpu.cpu.idle
End-of-File
else
cat <<End-of-File >>$tmp.conf
4 0 0.0 0.0 0.8 1000.0 user irix.kernel.percpu.cpu.user
3 0 0.8 0.0 0.0 1000.0 sys irix.kernel.percpu.cpu.sys
2 0 0.0 0.8 0.8 1000.0 wait irix.kernel.percpu.cpu.wait.total
1 0 0.0 0.8 0.0 1000.0 idle irix.kernel.percpu.cpu.idle
End-of-File
fi
else
# pmview 2.0
#
# create the list of cpus to be displayed - get inventory
#
eval `pmprobe $options -I irix.kernel.percpu.cpu.user 2>$tmp.err \
| sed \
-e 's/"//g' \
-e 's/$/ /' \
-e "s/^[^ ]* /ncpu=/" \
-e 's/ / cpulist="/' \
-e 's/"$/""/' \
-e 's/ $/"/'`
if [ -z "$cpulist" -o "$ncpu" -lt 1 ]
then
echo "Cannot get CPU inventory for host $host" >$tmp.msg
cat $tmp.err >>$tmp.msg
_pmview_error -f $tmp.msg
# NOTREACHED
fi
echo "$cpulist" | tr ' ' '\012' >$tmp.cpu
if [ -z "$cpuargs" ]
then
# sort list
#
if grep cpu: $tmp.cpu >/dev/null
then
# Origin series name style
cpulist=`sed -e 's/:/./' $tmp.cpu \
| sort -t. +1 -2n +2 -3n +3 -4 \
| sed -e 's/\./:/'`
else
# CPU names for older systems
cpulist=`sed -e 's/cpu/cpu./' $tmp.cpu \
| sort -t. +1 -2n \
| sed -e 's/\.//'`
fi
else
# restrict based on command line args
#
for cpu in $cpuargs
do
if grep "$cpu" $tmp.cpu >/dev/null
then
:
else
echo "CPU \"$cpu\" not in the CPU inventory ..." >$tmp.msg
fmt $tmp.cpu | sed -e 's/^/ /' >>$tmp.msg
_pmview_error -f $tmp.msg
# NOTREACHED
fi
done
cpulist="$cpuargs"
ncpu=`echo $cpulist | awk '{ print NF }'`
fi
# shape the base geometry for the scene
#
if [ $ncpu -le $maxrowlen ]
then
nrows=1
ncols=$ncpu
elif $force
then
nrows=`echo $ncpu $maxrowlen | nawk ' \
{ x = $1 / $2; y = $1 % $2; if (y > 0) ++x; printf "%d\n", x; }'`
ncols=$maxrowlen
else
case $algorithm in
a) # this algorithm doesn't work at the moment
# (the exit condition is not robust enough)
nrows=1
ncols=1
bound=1
num=0
while [ $num -gt $ncols -o $num -lt $bound ]
do
nrows=`expr $nrows \* 2`
ncols=`expr $ncpu / $nrows`
bound=`expr $ncols / 2`
num=`expr $nrows \* 4`
done
ncols=`echo $ncpu $nrows | nawk ' { x = $1 / $2; y = $1 % $2; \
if (y > 0) ++x; printf "%d\n", x }'`
;;
b)
# use a ratio for rows:columns of 1:8
#
nrows=`echo $ncpu | nawk ' { x = sqrt ($1 / 8.0);
y = int (x); if (y < x) ++y; print y }'`
ncols=`expr $ncpu + $nrows - 1`
ncols=`expr $ncols / $nrows`
;;
k)
nrows=`expr $ncpu + $maxrowlen - 1`
nrows=`expr $nrows / $maxrowlen`
ncols=`expr $ncpu + $nrows - 1`
ncols=`expr $ncols / $nrows`
esac
fi
cat <<End-of-File >$tmp.conf
pmview Version 2.0
#
# mpvis
#
#_scale 1.05
_gridSpace $gridspace
_gridHeight 2
End-of-File
if $have_intr
then
echo "_colorlist cpu ( green2 cyan2 yellow2 red2 blue2 )" >>$tmp.conf
else
echo "_colorlist cpu ( green2 cyan2 red2 blue2 )" >>$tmp.conf
fi
echo "_grid 0 0 hide ( # outer grid" >>$tmp.conf
# build rows from front-to-back of scene
# fill rows with CPUs from left-to-right
#
y=`expr $nrows \* 2 - 2`
col=0
rowlist=""
labels=""
for cpu in $cpulist
do
if [ $col -eq 0 ]
then
rowlist="$cpu"
else
rowlist="$rowlist,$cpu"
fi
$showinst && labels="$labels \"`echo $cpu | sed -e 's/cpu:*//'`\""
col=`expr $col + 1`
if [ $col -eq $ncols ]
then
_do_row
col=0
rowlist=""
labels=""
y=`expr $y - 2`
fi
done
[ $col -gt 0 ] && _do_row
echo ")" >>$tmp.conf
if [ $nrows -eq 1 ]
then
# remove unnecessary _grid for a single row
#
sed -e '/^ _grid/d' -e '/^ )/d' <$tmp.conf >$tmp.tmp
mv $tmp.tmp $tmp.conf
fi
fi
$verbose && cat $tmp.conf
eval pmview <$tmp.conf $args -title "'$titleArg'" -xrm "'*iconName: mpvis'"
exit